package validator;

import exceptions.InvalidUserNameException;
import exceptions.RequiredNameMissingException;
import exceptions.RequiredUserNameMissingException;

/**
 * Implements a validator of usernames
 * @author Alexandre, Cristovao, Raul, Rodolpho, Tales
 * @version 1.1
 * @milestone Number 2
 */
public class UserValidator {

	/**
	 * Checks if something was typed in username field
	 * @param userName
	 * @throws RequiredUserNameMissingException
	 */
	public static void checkMissingUserName(String userName)
			throws RequiredUserNameMissingException {
		if (userName == null || userName.trim() == "") {
			throw new RequiredUserNameMissingException(
					"Username eh um dado obrigatorio.");
		}
	}

	/**
	 * Check if something was typed in name field
	 * @param name
	 * @throws RequiredNameMissingException
	 */
	public static void checkMissingName(String name)
			throws RequiredNameMissingException {
		if (name == "" || name == null) {
			throw new RequiredNameMissingException(
					"Nome eh um dado obrigatorio.");
		}
	}

	/**
	 * Validates usernames
	 * @author Alexandre, Cristovao, Raul, Rodolpho, Tales
	 * @version 1.1
	 * @milestone Number 2
	 */
	public static void validateUserName(String userName)
			throws InvalidUserNameException {
		if (userName == null || userName.trim() == "") {
			throw new InvalidUserNameException(
					"Username invalido.");
		}
		
		if (userName.length() < 5) {
			throw new InvalidUserNameException(
					"User name deve ter no minimo 5 caracteres.");
		}
	}

	/**
	 * Checks and validates the username
	 * @param userName
	 * @throws RequiredUserNameMissingException
	 * @throws InvalidUserNameException
	 */
	public static void checkAndValidateUserName(String userName)
			throws RequiredUserNameMissingException, InvalidUserNameException {
		checkMissingUserName(userName);
		validateUserName(userName);
	}

}
